package com.heima.article.feign;

import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.feign.article.IArticleClient;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.article.dtos.ArticleCommentConfigDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.StatisticsDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
public class ArticleClient implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    /**
     * 保存app端文章
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/save")
    @Override
    public ResponseResult saveArticle(ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    @Override
    @PostMapping("/api/v1/article/newPage")
    public PageResponseResult newPage(@RequestBody StatisticsDto dto) {
        return apArticleService.newPage(dto);
    }


    @GetMapping("/api/v1/article/queryLikesAndConllections")
    @Override
    public ResponseResult queryLikesAndConllections(@RequestParam("wmUserId") Integer wmUserId,@RequestParam("beginDate") Date beginDate,@RequestParam("endDate") Date endDate) {
        return apArticleService.queryLikesAndConllections(wmUserId,beginDate,endDate);
    }

    /**
     * 查看评论列表
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/comment/manage/find_news_comments")
    public PageResponseResult findNewsComments(@RequestBody ArticleCommentDto dto){
        return apArticleConfigService.findNewsComments(dto);
    }

    /**
     * 根据id返回config状态表
     * @param id
     * @return
     */
    @PostMapping("/api/v1/article/comment/manage/find_config/{id}")
    public ResponseResult findConfig(@PathVariable("id") Long id){
        return apArticleConfigService.getConfig(id);
    }


    /**
     * 修改文章评论状态
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/comment/manage/updateCommentStatus")
    public ResponseResult updateCommentStatus(@RequestBody ArticleCommentConfigDto dto) {
        log.info("打印{}",dto);
        return apArticleConfigService.updateCommentStatus(dto);
    }
}
